package DMSXL._2023Before.Array;

/*public class sortedSquares {
    public static void main(String[] args) {
        int[] nums = {-7,-3,2,3,11};
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "  ");
        }
        Solution solution = new Solution();
        System.out.println();
        nums = solution.sortedSquares(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "  ");
        }
    }

}
class Solution {

    //左右
    /*public int[] sortedSquares(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int[] newarray = new int[right + 1];
        int index = right;
        while (left <= right){
            if(nums[left] * nums[left] > nums[right] * nums[right]){
                newarray[index--] = nums[left] * nums[left];
                left++;
            }
            else{
                newarray[index--] = nums[right] * nums[right];
                right--;
            }
        }
        return newarray;
    }*/

    //双指针
   /* public int[] sortedSquares(int[] nums) {

        int[] newarray = new int[nums.length];
        int neg = -1;
        for (int i = 0; i <= nums.length - 1 ; i++) {
            if(nums[i] < 0){
                neg++;
            }
        }
        int pos = neg + 1;
        int index = 0;
        while (neg >= 0 && pos <= nums.length - 1){
            if(nums[neg] * nums[neg] > nums[pos] * nums[pos]){
                newarray[index++] = nums[pos] * nums[pos];
                pos++;
            }
            else{
                newarray[index++] = nums[neg] * nums[neg];
                neg--;
            }
        }

        while(neg >= 0){
            newarray[index++] = nums[neg] * nums[neg];
            neg--;
        }
        while(pos <= nums.length - 1){
            newarray[index++] = nums[pos] * nums[pos];
            pos++;
        }
        return newarray;
    }

}
*/